package com.shuwang.goods.until;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by Riley on 2017/2/15.
 */
public class DTBuilder {

//    public final static String TimeStampToDatetime(Long date) {
//        SimpleDateFormat format =  new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
//        Long time=new Long(date);
//        return  format.format(time);
//    }
//
//    public final static String TimeStampToDate(Long date) throws ParseException {
//        SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd");
//        Long time=new Long(date);
//        String d = format.format(time);
//        return d;
//    }
//
//    public final static Date TimeStampToTime(Long date) throws ParseException {
//        SimpleDateFormat format =  new SimpleDateFormat("HH:mm:ss");
//        Long time=new Long(date);
//        String d = format.format(time);
//        return format.parse(d);
//    }
public final static Date TimeStampToDatetime(Long date) throws ParseException {
    SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Long time=new Long(date);
    String d = format.format(time);
    return format.parse(d);
}

    public final static Date TimeStampToTime(Long date) throws ParseException {
        SimpleDateFormat format =  new SimpleDateFormat("HH:mm:ss");
        Long time=new Long(date);
        String d = format.format(time);
        return format.parse(d);
    }

    public final static Date TimeStampToDate(Long date) throws ParseException {
        SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd");
        Long time=new Long(date);
        String d = format.format(time);
        return format.parse(d);
    }


    public final static String TimeStampToStringDate(Long date) throws ParseException {
        SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd");
        Long time=new Long(date);
        return format.format(time);
    }

    /**
     * 获取前一天的时间
     * @param date
     * @return
     */
    public static String getNextDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        String toDate = null;
        try {
            toDate = TimeStampToStringDate(calendar.getTime().getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return toDate;
    }


}
